package cn.zhonghuanzhiyuan.sprc.common.utils.redis;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * <p>className: RedisCacheUtil</p>
 * <p>description: </p>
 *
 * @author liuzhuo
 * @date 2021-6-2 14:26
 */
@Component
public class RedisHashUtil {

    private static final String PUSH_INFO_KEY = "PUSH_INFO_KEY_";
    // @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 存放任务信息
     */
    public void put(String group, String key, Object o) {
        redisTemplate.opsForHash().put(PUSH_INFO_KEY + group, key, o);
    }

    public Map<Object, Object> getAll(String group) {
        Map<Object, Object> entries = redisTemplate.opsForHash().entries(PUSH_INFO_KEY + group);
        return entries;
    }


    /**
     * 删除任务信息
     */
    public void delete(String group, String key) {

        redisTemplate.opsForHash().delete(PUSH_INFO_KEY + group, key);
    }


    public Object get(String group, String key) {
        return redisTemplate.opsForHash().get(PUSH_INFO_KEY + group, key);
    }


    public void delAll(String group) {
        redisTemplate.opsForHash().delete(PUSH_INFO_KEY + group);
    }

}